﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml;
using MPWebStream.MediaTranscoding;

namespace WebMediaPortal.Models
{
    public class StreamModel
    {
        public Resolution Size { get; set; }
        public string URL { get; set; }
    }

    public enum VideoPlayer
    {
        Flash,
        VLC
    }

    public enum StreamMedia
    {
        TV = -1,
        Movie = GmaWebService.Interfaces.MediaItemType.MovieItem,
        Serie = GmaWebService.Interfaces.MediaItemType.TvSeriesItem
    }

    public class TranscoderModel : TranscoderProfile
    {
        public int MaxOutputWidth { get; set; }
        public int MaxOutputHeight { get; set; }
        public string CodecParameters { get; set; }
        public VideoPlayer Player { get; set; }

        // this should be done better... I just don't know how (yet?)
        public TranscoderModel(TranscoderProfile profile)
        {
            this.InputMethod = profile.InputMethod;
            this.MIME = profile.MIME;
            this.Name = profile.Name;
            this.OutputMethod = profile.OutputMethod;
            this.Parameters = profile.Parameters;
            this.Transcoder = profile.Transcoder;
            this.UseTranscoding = profile.UseTranscoding;
        }

        public static List<TranscoderModel> List()
        {
            List<TranscoderModel> list = new List<TranscoderModel>();
            XmlDocument doc = new XmlDocument();
            doc.Load(AppDomain.CurrentDomain.BaseDirectory + "config.transcoder.xml");
            XmlNodeList nodes = doc.SelectNodes("/transcoderconfig/transcoder");
            foreach (XmlNode node in nodes)
            {
                TranscoderModel transcoder = new TranscoderModel(TranscoderProfile.CreateFromXmlNode(node));
                foreach (XmlNode child in node.ChildNodes)
                {
                    if (child.Name == "player") transcoder.Player = (VideoPlayer)Enum.Parse(typeof(VideoPlayer), child.InnerText, true);
                    if (child.Name == "maxOutputWidth") transcoder.MaxOutputWidth = Int32.Parse(child.InnerText);
                    if (child.Name == "maxOutputHeight") transcoder.MaxOutputHeight = Int32.Parse(child.InnerText);
                    if (child.Name == "codecParameters") transcoder.CodecParameters = child.InnerText;
                }
                list.Add(transcoder);
            }
            return list;
        }
    }
}